form - input


Posted by mijouhsieh on 2023-03-31

form送出後,清除input的值 searchInput.value = ""

CODEPEN LINK

 <form id="search-form">
    <label for="search-input"> input something </label>
    <input type="text" id="search-input" placeholder="text..." />
    <button id="addBtn"> ADD </button>
</form>
searchForm.addEventListener("submit", function addItem(event) {
  event.preventDefault();
  const item = searchInput.value.trim();
  // searchInput.innerText = '' // 是抓value屬性,改innerText無效
  searchInput.value = "";
  if (!item.length) return;
  showItemToScreen(item);
});

#searchInput.value #clear input value







Related Posts

[ week 1 ] Command Line 使用方法

[ week 1 ] Command Line 使用方法

[ 筆記 ] JavaScript 進階 08 - new、extends、super、封裝

[ 筆記 ] JavaScript 進階 08 - new、extends、super、封裝

[ Vue筆記 ] Vue使用setInterval

[ Vue筆記 ] Vue使用setInterval


Comments